package hotel.modal;

import hotel.dao.RoomReserveDao;
import javafx.beans.property.*;

public class RoomReserve {
	private SimpleStringProperty reserveId; 	// 预定单号
	private SimpleStringProperty presetTime;	// 预定时间
	private SimpleStringProperty roomNo;		// 预定房间编号
	private SimpleIntegerProperty duration;		// 预定时长
	private SimpleIntegerProperty holdTime;		// 保留时长
	private SimpleDoubleProperty deposit;		// 预收金额
	private SimpleStringProperty name;			// 联系人
	private SimpleStringProperty phone;			// 联系电话
	private SimpleStringProperty createTime;	// 创建时间
	private SimpleBooleanProperty valid;		// 是否有效
	private SimpleStringProperty comment;		// 备注
	protected SimpleBooleanProperty modified;
	
	private void init(RoomReserveDao rrd) {
		if(rrd != null) {
			this.reserveId = new SimpleStringProperty(rrd.getReserveId());
			this.presetTime = new SimpleStringProperty(rrd.getPresetTime());
			this.roomNo = new SimpleStringProperty(rrd.getRoomNo());
			this.duration = new SimpleIntegerProperty(rrd.getDuration());
			this.holdTime = new SimpleIntegerProperty(rrd.getHoldTime());
			this.deposit = new SimpleDoubleProperty(rrd.getDeposit());
			this.name = new SimpleStringProperty(rrd.getName());
			this.phone = new SimpleStringProperty(rrd.getPhone());
			this.createTime = new SimpleStringProperty(rrd.getCreateTime());
			this.valid = new SimpleBooleanProperty(rrd.isValid());
			this.comment = new SimpleStringProperty(rrd.getComment());
		}else {
			this.reserveId = new SimpleStringProperty("");
			this.presetTime = new SimpleStringProperty("");
			this.roomNo = new SimpleStringProperty("");
			this.duration = new SimpleIntegerProperty(0);
			this.holdTime = new SimpleIntegerProperty(0);
			this.deposit = new SimpleDoubleProperty(0.0);
			this.name = new SimpleStringProperty("");
			this.phone = new SimpleStringProperty("");
			this.createTime = new SimpleStringProperty("");
			this.valid = new SimpleBooleanProperty(true);
			this.comment = new SimpleStringProperty("");
		}
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public RoomReserve(RoomReserveDao rrd) {
		init(rrd);
	}
	
	public RoomReserve() {
		init(null);
	}
	
	public Object getDao() {
		RoomReserveDao rrd = new RoomReserveDao();
		rrd.setReserveId(reserveId.get());
		rrd.setPresetTime(presetTime.get());
		rrd.setRoomNo(roomNo.get());
		rrd.setDuration(duration.get());
		rrd.setHoldTime(holdTime.get());
		rrd.setDeposit(deposit.get());
		rrd.setName(name.get());
		rrd.setPhone(phone.get());
		rrd.setCreateTime(createTime.get());
		rrd.setValid(valid.get());
		rrd.setComment(comment.get());
		return rrd;
	}
	
	public RoomReserve(RoomReserve roomReserve) {
		this.reserveId = new SimpleStringProperty(roomReserve.getReserveId());
		this.presetTime = new SimpleStringProperty(roomReserve.getPresetTime());
		this.roomNo = new SimpleStringProperty(roomReserve.getRoomNo());
		this.duration = new SimpleIntegerProperty(roomReserve.getDuration());
		this.holdTime = new SimpleIntegerProperty(roomReserve.getHoldTime());
		this.deposit = new SimpleDoubleProperty(roomReserve.getDeposit());
		this.name = new SimpleStringProperty(roomReserve.getName());
		this.phone = new SimpleStringProperty(roomReserve.getPhone());
		this.createTime = new SimpleStringProperty(roomReserve.getCreateTime());
		this.valid = new SimpleBooleanProperty(roomReserve.isValid());
		this.comment = new SimpleStringProperty(roomReserve.getComment());
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public RoomReserve(String reserveId, String presetTime, String roomNo, int duration,
			int holdTime, double deposit, String name, String phone, String createTime, int valid, String comment) {
		this.reserveId = new SimpleStringProperty(reserveId);
		this.presetTime = new SimpleStringProperty(presetTime);
		this.roomNo = new SimpleStringProperty(roomNo);
		this.duration = new SimpleIntegerProperty(duration);
		this.holdTime = new SimpleIntegerProperty(holdTime);
		this.deposit = new SimpleDoubleProperty(deposit);
		this.name = new SimpleStringProperty(name);
		this.phone = new SimpleStringProperty(phone);
		this.createTime = new SimpleStringProperty(createTime);
		if(valid > 0) this.valid = new SimpleBooleanProperty(true);
		else this.valid = new SimpleBooleanProperty(false);
		this.comment = new SimpleStringProperty(comment);
		this.modified = new SimpleBooleanProperty(false);
	}
	
	@Override
	public String toString() {
		String str = String.format("ReserveId:%s PresetTime:%s RoomNo:%s Duration:%d HoldTime:%s" +
				"Deposit:%.2f Name:%s Phone:%s CreateTime:%s Valid:%s Comment:%s", 
				reserveId.get(), presetTime.get(), roomNo.get(), duration.get(), holdTime.get(),
				deposit.get(), name.get(), phone.get(), createTime.get(), valid.get(), comment.get());
		return str;
	}
	
	public final SimpleStringProperty reserveIdProperty() {
		return this.reserveId;
	}
	
	public final String getReserveId() {
		return this.reserveIdProperty().get();
	}
	
	public final void setReserveId(final String reserveId) {
		this.reserveIdProperty().set(reserveId);
	}
	
	public final SimpleStringProperty presetTimeProperty() {
		return this.presetTime;
	}
	
	public final String getPresetTime() {
		return this.presetTimeProperty().get();
	}
	
	public final void setPresetTime(final String presetTime) {
		this.presetTimeProperty().set(presetTime);
	}
	
	public final SimpleStringProperty roomNoProperty() {
		return this.roomNo;
	}
	
	public final String getRoomNo() {
		return this.roomNoProperty().get();
	}
	
	public final void setRoomNo(final String roomNo) {
		this.roomNoProperty().set(roomNo);
	}
	
	public final SimpleIntegerProperty durationProperty() {
		return this.duration;
	}
	
	public final int getDuration() {
		return this.durationProperty().get();
	}
	
	public final void setDuration(final int duration) {
		this.durationProperty().set(duration);
	}
	
	public final SimpleDoubleProperty depositProperty() {
		return this.deposit;
	}
	
	public final double getDeposit() {
		return this.depositProperty().get();
	}
	
	public final void setDeposit(final double deposit) {
		this.depositProperty().set(deposit);
	}
	
	public final SimpleStringProperty nameProperty() {
		return this.name;
	}
	
	public final String getName() {
		return this.nameProperty().get();
	}
	
	public final void setName(final String name) {
		this.nameProperty().set(name);
	}
	
	public final SimpleStringProperty phoneProperty() {
		return this.phone;
	}
	
	public final String getPhone() {
		return this.phoneProperty().get();
	}
	
	public final void setPhone(final String phone) {
		this.phoneProperty().set(phone);
	}
	
	public final SimpleStringProperty createTimeProperty() {
		return this.createTime;
	}
	
	public final String getCreateTime() {
		return this.createTimeProperty().get();
	}
	
	public final void setCreateTime(final String createTime) {
		this.createTimeProperty().set(createTime);
	}
	
	public final SimpleBooleanProperty validProperty() {
		return this.valid;
	}
	
	public final boolean isValid() {
		return this.validProperty().get();
	}
	
	public final void setValid(final boolean valid) {
		this.validProperty().set(valid);
	}
	
	public final SimpleStringProperty commentProperty() {
		return this.comment;
	}
	
	public final String getComment() {
		return this.commentProperty().get();
	}
	
	public final void setComment(final String comment) {
		this.commentProperty().set(comment);
	}

	public final SimpleBooleanProperty modifiedProperty() {
		return this.modified;
	}
	

	public final boolean isModified() {
		return this.modifiedProperty().get();
	}
	

	public final void setModified(final boolean modified) {
		this.modifiedProperty().set(modified);
	}

	public final SimpleIntegerProperty holdTimeProperty() {
		return this.holdTime;
	}
	

	public final int getHoldTime() {
		return this.holdTimeProperty().get();
	}
	

	public final void setHoldTime(final int holdTime) {
		this.holdTimeProperty().set(holdTime);
	}
	
	
}
